/**
 * Lop mui ten nay xu ly cac van de lien quan den mui ten trong game
 */
package model.entity;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;
import java.util.ArrayList;
import java.util.List;

import javax.swing.ImageIcon;

import model.Constant;

/**
 * @author heroandtn3
 * @date Oct 27, 2012
 */
public class Arrows {
	private int row, col;
	private int typeID;
	private String urlID;
	private List<Integer> types;
	private Image shape;

	/**
	 * 
	 */
	public Arrows(int row, int col, int value, String urlID) {
		// TODO Auto-generated constructor stub
		this.row = row;
		this.col = col;
		this.urlID = urlID;
		this.typeID = 0;
		this.initType(value);
		this.shape = new ImageIcon(Constant.ARR_DIR + urlID + "/" + types.get(typeID)).getImage();
	}
	
	private void initType(int value) {
		types = new ArrayList<Integer>();
		
		if ((value & 1) == 1) {
			types.add(1);
		}
		
		if ((value & 2) == 2) {
			types.add(2);
		}
		
		if ((value & 4) == 4) {
			types.add(4);
		}
		
		if ((value & 8) == 8) {
			types.add(8);
		}
		this.typeID = (int) (Math.random() * types.size());
	}
	
	public void nextType() {
		// chuyen gia tri cua mui ten sang gia tri tiep theo
		typeID = (typeID+1) % types.size();
		this.shape = new ImageIcon(Constant.ARR_DIR + urlID + "/" + types.get(typeID)).getImage();
	}
	
	public int getType() {
		return types.get(typeID);
	}

	/**
	 * @return the row
	 */
	public int getRow() {
		return row;
	}

	/**
	 * @param row the row to set
	 */
	public void setRow(int row) {
		this.row = row;
	}

	/**
	 * @return the col
	 */
	public int getCol() {
		return col;
	}

	/**
	 * @param col the col to set
	 */
	public void setCol(int col) {
		this.col = col;
	}

	/**
	 * @return the shape
	 */
	public Image getShape() {
		return shape;
	}

	/**
	 * @param shape the shape to set
	 */
	public void setShape(Image shape) {
		this.shape = shape;
	}

	// paint itseft
	public void paint(Graphics2D g2d) {
		g2d.setColor(Color.WHITE);
		g2d.fill3DRect(Constant.PADDING + col * Constant.CELL_SIZE, 
				Constant.PADDING + row * Constant.CELL_SIZE,
				Constant.BOX_SIZE, Constant.BOX_SIZE, 
				true);
		g2d.drawImage(shape, 
				col * Constant.CELL_SIZE + 4, row * Constant.CELL_SIZE + 4,
				null);
	}
}
